/*
 * DBeaver - Universal Database Manager
 * Copyright (C) 2010-2024 DBeaver Corp and others
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jkiss.dbeaver.ext.altibase.model;

import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.ext.generic.model.GenericProcedure;
import org.jkiss.dbeaver.ext.generic.model.GenericProcedureParameter;
import org.jkiss.dbeaver.model.impl.DBPositiveNumberTransformer;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameterKind;

public class AltibaseProcedureParameter extends GenericProcedureParameter {

    public static final int PARAM_IN    = 0;
    public static final int PARAM_OUT   = 1;
    public static final int PARAM_INOUT = 2;

    // Constructor with GenericProcedureParameter
    public AltibaseProcedureParameter(GenericProcedureParameter param) {
        super(param.getParentObject(),
                param.getName(),
                param.getTypeName(),
                param.getTypeID(),
                param.getOrdinalPosition(),
                (int) param.getMaxLength(),
                param.getScale(),
                param.getPrecision(),
                param.isRequired(),
                param.getDescription(),
                param.getParameterKind());
    }

    public AltibaseProcedureParameter(
            GenericProcedure procedure,
            String columnName,
            String typeName,
            int valueType,
            int ordinalPosition,
            int columnSize,
            Integer scale,
            Integer precision,
            boolean notNull,
            String remarks,
            DBSProcedureParameterKind parameterKind) {
        super(procedure, columnName, typeName, valueType, ordinalPosition, columnSize, scale, precision, 
                notNull, remarks, parameterKind);
    }

    @Nullable
    @Override
    @Property(viewable = true, valueRenderer = DBPositiveNumberTransformer.class, order = 42)
    public Integer getPrecision() {
        return precision == -1 ? null : precision;
    }

    @Override
    @Property(viewable = true, valueRenderer = DBPositiveNumberTransformer.class, order = 41)
    public Integer getScale() {
        return scale == -1 ? null : scale;
    }

    @Override
    @Property(viewable = true, order = 43)
    public boolean isRequired() {
        return required;
    }

    /*
     * Hide: Altibase doesn't support comment for procedure and parameter
     */
    @Override
    @Property(viewable = false, hidden = true, order = 55)
    public boolean isAutoGenerated() {
        return autoGenerated;
    }
}
